﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using BrnMall.Core;
using BrnMall.Manager.Domain.Store;
using BrnMall.Manager.Manager.Store;
using BrnMall.Services;
using BrnMall.Web.Framework;
using BrnMall.Web.StoreAdmin.Models;

namespace BrnMall.Web.StoreAdmin.controllers
{
    public class SetController:BaseStoreAdminController
    {
        /// <summary>
        /// 积分
        /// </summary>
        [HttpGet]
        public ActionResult Credit()
        {
            var creditConfigInfo = StoreConfigManager.GetStoreCreditConfigInfo(WorkContext.StoreId);

            var model = new CreditModel
            {
                Id = creditConfigInfo.Id,
                StoreId = creditConfigInfo.StoreId,
                PayCreditName = creditConfigInfo.PayCreditName,
                PayCreditPrice = creditConfigInfo.PayCreditPrice,
                DayMaxSendPayCredits = creditConfigInfo.DayMaxSendPayCredits,
                OrderMaxUsePayCredits = creditConfigInfo.OrderMaxUsePayCredits,
                RegisterPayCredits = creditConfigInfo.RegisterPayCredits,
                LoginPayCredits = creditConfigInfo.LoginPayCredits,
                VerifyEmailPayCredits = creditConfigInfo.VerifyEmailPayCredits,
                VerifyMobilePayCredits = creditConfigInfo.VerifyMobilePayCredits,
                CompleteUserInfoPayCredits = creditConfigInfo.CompleteUserInfoPayCredits,
                ReceiveOrderPayCredits = creditConfigInfo.ReceiveOrderPayCredits,
                ReviewProductPayCredits = creditConfigInfo.ReviewProductPayCredits,
                RankCreditName = creditConfigInfo.RankCreditName,
                DayMaxSendRankCredits = creditConfigInfo.DayMaxSendRankCredits,
                RegisterRankCredits = creditConfigInfo.RegisterRankCredits,
                LoginRankCredits = creditConfigInfo.LoginRankCredits,
                VerifyEmailRankCredits = creditConfigInfo.VerifyEmailRankCredits,
                VerifyMobileRankCredits = creditConfigInfo.VerifyMobileRankCredits,
                CompleteUserInfoRankCredits = creditConfigInfo.CompleteUserInfoRankCredits,
                ReceiveOrderRankCredits = creditConfigInfo.ReceiveOrderRankCredits,
                ReviewProductRankCredits = creditConfigInfo.ReviewProductRankCredits
            };


            return View(model);
        }

        /// <summary>
        /// 积分
        /// </summary>
        [HttpPost]
        public ActionResult Credit(CreditModel model)
        {
            if (ModelState.IsValid)
            {
                var creditConfigInfo = StoreConfigManager.GetStoreCreditConfigInfo(WorkContext.StoreId);

                creditConfigInfo.PayCreditName = model.PayCreditName;
                creditConfigInfo.PayCreditPrice = model.PayCreditPrice;
                creditConfigInfo.DayMaxSendPayCredits = model.DayMaxSendPayCredits;
                creditConfigInfo.OrderMaxUsePayCredits = model.OrderMaxUsePayCredits;
                creditConfigInfo.RegisterPayCredits = model.RegisterPayCredits;
                creditConfigInfo.LoginPayCredits = model.LoginPayCredits;
                creditConfigInfo.VerifyEmailPayCredits = model.VerifyEmailPayCredits;
                creditConfigInfo.VerifyMobilePayCredits = model.VerifyMobilePayCredits;
                creditConfigInfo.CompleteUserInfoPayCredits = model.CompleteUserInfoPayCredits;
                creditConfigInfo.ReceiveOrderPayCredits = model.ReceiveOrderPayCredits;
                creditConfigInfo.ReviewProductPayCredits = model.ReviewProductPayCredits;

                creditConfigInfo.RankCreditName = model.RankCreditName;
                creditConfigInfo.DayMaxSendRankCredits = model.DayMaxSendRankCredits;
                creditConfigInfo.RegisterRankCredits = model.RegisterRankCredits;
                creditConfigInfo.LoginRankCredits = model.LoginRankCredits;
                creditConfigInfo.VerifyEmailRankCredits = model.VerifyEmailRankCredits;
                creditConfigInfo.VerifyMobileRankCredits = model.VerifyMobileRankCredits;
                creditConfigInfo.CompleteUserInfoRankCredits = model.CompleteUserInfoRankCredits;
                creditConfigInfo.ReceiveOrderRankCredits = model.ReceiveOrderRankCredits;
                creditConfigInfo.ReviewProductRankCredits = model.ReviewProductRankCredits;

               StoreConfigManager.UpdateStoreCreditConfigInfo(creditConfigInfo);
                AddStoreAdminLog("修改积分设置");
                return PromptView(Url.Action("credit"), "修改积分设置成功");
            }
            return View(model);
        }
    }
}
